package com.ruoyi.buss.group.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.buss.group.domain.DataCustomerGroupRelation;
import com.ruoyi.buss.group.service.IDataCustomerGroupRelationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 客户和群体关系Controller
 * 
 * @author sxy
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/groupRelation")
public class DataCustomerGroupRelationController extends BaseController
{
    @Autowired
    private IDataCustomerGroupRelationService dataCustomerGroupRelationService;

    /**
     * 查询客户和群体关系列表
     */
    @PreAuthorize(hasPermi = "buss:groupRelation:list")
    @GetMapping("/list")
    public TableDataInfo list(DataCustomerGroupRelation dataCustomerGroupRelation)
    {
        startPage();
        List<DataCustomerGroupRelation> list = dataCustomerGroupRelationService.selectDataCustomerGroupRelationList(dataCustomerGroupRelation);
        return getDataTable(list);
    }

    /**
     * 导出客户和群体关系列表
     */
    @PreAuthorize(hasPermi = "buss:groupRelation:export")
    @Log(title = "客户和群体关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCustomerGroupRelation dataCustomerGroupRelation) throws IOException
    {
        List<DataCustomerGroupRelation> list = dataCustomerGroupRelationService.selectDataCustomerGroupRelationList(dataCustomerGroupRelation);
        ExcelUtil<DataCustomerGroupRelation> util = new ExcelUtil<DataCustomerGroupRelation>(DataCustomerGroupRelation.class);
        util.exportExcel(response, list, "客户和群体关系数据");
    }

    /**
     * 获取客户和群体关系详细信息
     */
    @PreAuthorize(hasPermi = "buss:groupRelation:query")
    @GetMapping(value = "/{idCard}")
    public AjaxResult getInfo(@PathVariable("idCard") String idCard)
    {
        return AjaxResult.success(dataCustomerGroupRelationService.selectDataCustomerGroupRelationById(idCard));
    }

    /**
     * 新增客户和群体关系
     */
    @PreAuthorize(hasPermi = "buss:groupRelation:add")
    @Log(title = "客户和群体关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCustomerGroupRelation dataCustomerGroupRelation)
    {
        return toAjax(dataCustomerGroupRelationService.insertDataCustomerGroupRelation(dataCustomerGroupRelation));
    }

    /**
     * 修改客户和群体关系
     */
    @PreAuthorize(hasPermi = "buss:groupRelation:edit")
    @Log(title = "客户和群体关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCustomerGroupRelation dataCustomerGroupRelation)
    {
        return toAjax(dataCustomerGroupRelationService.updateDataCustomerGroupRelation(dataCustomerGroupRelation));
    }

    /**
     * 删除客户和群体关系
     */
    @PreAuthorize(hasPermi = "buss:groupRelation:remove")
    @Log(title = "客户和群体关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idCards}")
    public AjaxResult remove(@PathVariable String[] idCards)
    {
        return toAjax(dataCustomerGroupRelationService.deleteDataCustomerGroupRelationByIds(idCards));
    }
}
